<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <title>查询老师信息</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        h2 {
            text-align: center;
            margin-bottom: 20px;
        }
        .top-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .search-box {
            flex-grow: 1;
            position: relative;
            width:100px;

        }
        .search-box input[type="text"] {
            padding: 10px 20px;
            width: calc(100% - 40px);
            border: 2px solid #ddd;
            border-radius: 5px;
            outline: none;
            transition: border-color 0.3s;
        }
        .search-box input[type="text"]:focus {
            border-color: #007bff;
        }
        .search-box button {
            position: absolute;
            left:13%;
            top: 50%;
            transform: translateY(-50%);
            padding: 8px 15px;
            border: none;
            background-color: #007bff;
            color: white;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;

        }
        .search-box button:hover {
            background-color: #0056b3;
        }
        .pagination {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 20px;
        }
        .pagination a, .pagination select {
            margin: 0 5px;
            padding: 5px 10px;
            text-decoration: none;
            border: 1px solid #ddd;
            color: #007bff;
            border-radius: 5px;
            transition: background-color 0.3s, color 0.3s;
        }
        .pagination a:hover, .pagination select:hover {
            background-color: #007bff;
            color: white;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h2>查询老师信息</h2>

<div class="top-bar">
    <div class="search-box">
        <form action="${pageContext.request.contextPath}/teacherquerybyname" method="get">
            <input type="text" id="tname" name="tname" placeholder="输入老师名字" style="width: 150px;">
            <button type="submit">查询</button>
        </form>
    </div>
</div>

<table>
    <thead>
    <tr>
        <th>编号</th>
        <th>名字</th>
        <th>年龄</th>
        <th>性别</th>
        <th>地址</th>
        <th>电话</th>
        <th>职业</th>
        <th>学院</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach var="teacher" items="${teachers}">
        <tr>
            <td>${teacher.tid}</td>
            <td>${teacher.tname}</td>
            <td>${teacher.age}</td>
            <td>${teacher.gender == 'M' ? '男' : '女'}</td>
            <td>${teacher.address}</td>
            <td>${teacher.phone}</td>
            <td>${teacher.profession}</td>
            <td>${teacher.academy}</td>
        </tr>
    </c:forEach>
    </tbody>
</table>

<div class="pagination">
    <form id="pageSizeForm" action="teacherpagequery" method="get">
        <label for="pageSize">每页显示:</label>
        <select id="pageSize" name="pageSize" onchange="document.getElementById('pageSizeForm').submit()">
            <option value="5" ${pageSize == 5 ? 'selected' : ''}>5</option>
            <option value="10" ${pageSize == 10 ? 'selected' : ''}>10</option>
            <option value="15" ${pageSize == 15 ? 'selected' : ''}>15</option>
        </select>
        <input type="hidden" name="page" value="${currentPage}" />
    </form>

    <c:forEach var="i" begin="1" end="${totalPage}">
        <a href="teacherpagequery?page=${i}&pageSize=${pageSize}" ${currentPage == i ? 'style="font-weight:bold"' : ''}>${i}</a>
    </c:forEach>
</div>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        if (!window.location.search) {
            window.location.href = "teacherpagequery?page=1&pageSize=10";
        }
    });
</script>


</body>
</html>
